package android.alliance.inappbilling;

import android.alliance.inappbilling.BillingService.RequestPurchase;
import android.alliance.inappbilling.BillingService.RestoreTransactions;
import android.alliance.inappbilling.Consts.PurchaseState;
import android.alliance.inappbilling.Consts.ResponseCode;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.util.Log;

public class AlliancePurchaseObserver extends PurchaseObserver {

	public AlliancePurchaseObserver(Activity activity, Handler handler) {
		super(activity, handler);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onBillingSupported(boolean supported, String type) {

		if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) {
			if (supported) {
				Log.d("#", "supported");
				
				// Boy Button enable
	        } else {
	        	Log.d("#", "Not supported");
//	        	showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
	        }	
		} else if (type.equals(Consts.ITEM_TYPE_SUBSCRIPTION)) {
//            mCatalogAdapter.setSubscriptionsSupported(supported);
        } else {
//            showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
        }
		
		
	}

	@Override
	public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) {
	   if (developerPayload == null) {
//           logProductActivity(itemId, purchaseState.toString());
       } else {
//           logProductActivity(itemId, purchaseState + "\n\t" + developerPayload);
       }

       if (purchaseState == PurchaseState.PURCHASED) {
//           mOwnedItems.add(itemId);
       }
//       mCatalogAdapter.setOwnedItems(mOwnedItems);
//       mOwnedItemsCursor.requery();
		
	}

	@Override
	public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) {
         if (responseCode == ResponseCode.RESULT_OK) {
        	 Log.d("#", "Result ok");
//             logProductActivity(request.mProductId, "sending purchase request");
         } else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {
        	 Log.d("#", "Result User cancled");
//             logProductActivity(request.mProductId, "dismissed purchase dialog");
         } else {
        	 Log.d("#", "Result other");
//             logProductActivity(request.mProductId, "request purchase returned " + responseCode);
         }
	}

	@Override
	public void onRestoreTransactionsResponse(RestoreTransactions request, ResponseCode responseCode) {
		 if (responseCode == ResponseCode.RESULT_OK) {
			 Log.d("#", "Result ok");
			 
             // Update the shared preferences so that we don't perform
             // a RestoreTransactions again.
//             SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
//             SharedPreferences.Editor edit = prefs.edit();
//             edit.putBoolean(DB_INITIALIZED, true);
//             edit.commit();
         } else {
        	 Log.d("#", "Result error");         }
	}
}